//
//  WYTXViewController.m
//  VmiSJ
//
//  Created by 汪的一声就哭了！ on 2017/1/10.
//  Copyright © 2017年 汪的一声就哭了！. All rights reserved.
//

#import "WYTXViewController.h"

@interface WYTXViewController ()<UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UITextField *firstTF;
@property (strong, nonatomic) IBOutlet UITextField *secTF;
@property (strong, nonatomic) IBOutlet UITextField *thirdTF;
@property (strong, nonatomic) IBOutlet UITextField *forthTF;
@property (strong, nonatomic) IBOutlet UILabel *btnLabel;

@end

@implementation WYTXViewController
{
    //发送验证码倒计时
    NSTimer *_djsTimer;
    NSInteger _daojishi;
}
- (IBAction)sureAction:(UIButton *)sender {
    if ([self.firstTF.text isEqualToString:@""]) {
        [[SQShowMessage shareMessage] showMessageWithStr:@"请输入金额"];
    } else if ([self.secTF.text isEqualToString:@""]) {
        [[SQShowMessage shareMessage] showMessageWithStr:@"请输入支付宝账号"];
    } else if ([self.thirdTF.text isEqualToString:@""]) {
        [[SQShowMessage shareMessage] showMessageWithStr:@"请输入支付宝姓名"];
    } else if ([self.forthTF.text isEqualToString:@""]) {
        [[SQShowMessage shareMessage] showMessageWithStr:@"请输入验证码"];
    } else {
    [NetRequiest handleDataWithString:[NSString stringWithFormat:@"%@/Business/bringmoney",HTTPLOAD] dictionary:@{@"v1":@"bringmoney",@"uid":UID,@"change_money":self.firstTF.text,@"code":self.forthTF.text,@"pay_account":self.secTF.text,@"name":self.thirdTF.text} HUD:YES block:^(id responseObject) {
        if ([responseObject[@"code"] isEqual:@200]) {
            [self.navigationController popViewControllerAnimated:YES];
        }
        [[SQShowMessage shareMessage] showMessageWithStr:responseObject[@"msg"]];
    }];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"我要提现";
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    tap.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tap];
    
    UITapGestureRecognizer *yzmTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sendYZMAction:)];
    [self.btnLabel addGestureRecognizer:yzmTap];
}
- (void)tapAction:(UITapGestureRecognizer *)tap
{
    [self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == self.firstTF) {
        [self.firstTF resignFirstResponder];
        [self.secTF becomeFirstResponder];
    }
    if (textField == self.secTF) {
        [self.secTF resignFirstResponder];
        [self.thirdTF becomeFirstResponder];
    }
    if (textField == self.thirdTF) {
        [self.thirdTF resignFirstResponder];
        [self.forthTF becomeFirstResponder];
    }
    if (textField == self.forthTF) {
        [self.view endEditing:YES];
    }
    return YES;
}
#pragma mark ------------ 发送验证码
- (void)sendYZMAction:(UITapGestureRecognizer *)tap
{
    [NetRequiest handleDataWithString:[NSString stringWithFormat:@"%@/Sms/sendsms",HTTPLOAD] dictionary:@{@"uid":UID,@"star":@"bringmoney"} block:^(id responseObject) {
            if ([responseObject[@"code"] isEqual:@200]) {
                self.btnLabel.backgroundColor = [UIColor colorWithRed:198.0/255.0 green:199.0/255.0 blue:205.0/255.0 alpha:1];
                self.btnLabel.text = @"重新发送(60s)";
                _daojishi = 60;
                _djsTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(djsTimerAction:) userInfo:nil repeats:YES];
                self.btnLabel.userInteractionEnabled = NO;
            } else {
                [[SQShowMessage shareMessage] showMessageWithStr:responseObject[@"msg"]];
            }
    }];
}
#pragma mark ---------- 发送验证码倒计时
- (void)djsTimerAction:(NSTimer *)timer
{
    _daojishi--;
    NSString *str = [NSString stringWithFormat:@"重新发送(%ld)",_daojishi];
    self.btnLabel.text = str;
    if (_daojishi == 0) {
        [_djsTimer invalidate];
        self.btnLabel.backgroundColor = Color;
        self.btnLabel.userInteractionEnabled = YES;
        self.btnLabel.text = @"发送验证码";
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
